
<?
include("lib.php");
$user   = $_GET['user'];

function days_in_month($month, $year)
{
// calculate number of days in a month
return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);
} 

$curYear  = date("Y");
$curMonth = date("n");
$curDay   = date("j");

$maxMonth = 12;

echo("<a href='index.php?user=$user'>back</a><br> ");

for($year = 2013; $year <= $curYear ; $year++) 
  {
    $xx = readCurrentSum($user,$year);
    echo("<a href='stat.php?user=$user&year=$year'>$year</a>  $xx kWh<br> ");
    if($curYear == $year)$maxMonth = $curMonth;
    for($month=1;$month<=$maxMonth;$month++)
      {
	$temp = addZero($month);
	$temp = $year.'-'.$temp;
	$xx = readCurrentSum($user,$temp);
	$maxDay = days_in_month($month,$year);
	if($curYear == $year && $curMonth == $month)$maxDay = $curDay;
	echo("<a href='stat.php?user=$user&month=$month'>$month </a> $xx kWh<br> ");
	for($ii = 1; $ii <= $maxDay; $ii++)
	  echo("<a href='stat.php?user=$user&day=$ii'>$ii</a> ");
	
	echo("<br>");
      }
  }

?>